#!/bin/bash

# 配置项
CACHE_DIR="${HOME}/.cache/chillhop-player"
FFPLAY_PATH="ffplay"
STREAM_BASE_URL="https://stream.chillhop.com/mp3/"
DMENU_ARGS="-i -c"

# 嵌入的曲目列表（由 generate_chillhop_menu.sh 自动生成）
TRACKS=$(cat <<'TRACK_EOF'
9476!Apple Juice
8448!Tôzen
8878!Swiss
8603!Like This One, & Then Some
8598!Secret Meetings
8596!Fluid Dynamics
8562!Theme From Endless Sunset
8591!Outskirts
8587!Squba
8582!The Story
8769!OdeToYou
8788!Pueblo
8905!Fade
8908!Trouble
8941!With You
8938!Lego
8924!Orbit
8935!Thoughts
8932!Lament
8931!Moods
8927!Doin It
8925!Snapback
8922!Green Stamps
8921!Twrk
8917!Floating Vibes
8914!Waves
8912!Sometimesoon
8909!Tell Me
8943!Wondering
8906!Soundscapes
8421!Wine & Roses
8464!Underwater
8221!The Creator
8467!Cloud Steps
8459!Breathless
48099!The God Behind The Pines
9026!Staying There
48100!Urban Canopy
9022!Her
8990!Spring Vale
9097!Reefs
9094!Driftwood
9091!Motions
9089!Azure
9131!Boys' Bop
8518!The End
9154!Heartburn
9151!Rematch
8440!Leavin'
9149!Sodium
9146!Frameworks, Pt.2
9144!Rebirth
9140!RealEstate
9138!Trust
8298!Hope
9136!Frameworks, Pt.1
8780!Flke
9133!Clockwork
8122!Blue
8533!Birth
8940!Saudade
8472!Evening Tide
8947!Nowhere Else
8942!Trip To The Mountains
8944!Mercadia
8950!Can You See The Rhino In The Clouds?
8936!Thoughts
8255!Hold My Hand
8937!New Beginnings
9213!Farewell
8358!There.Is.A.Place
47674!T00.Mch_t00.Lttl
8661!Albedo
8187!Vscrl_
9207!Brzzy_bump
9109!Imgnry
8415!Raft
9205!Hijack
9204!Black[Ice]
9202!Permafr0st
8960!Dw3ll
9201!Skyrate
8349!Isla Bella
8303!Indelible
8730!Everydayluvin
9252!Yesorno
9249!Remember
8412!Nomatter
9246!Chances
9067!Backhome
9244!Menti
8748!Bravo
8929!Steady
8470!Movie Scene
9194!Horizons Form From The Soul
8915!Requiem
9256!Sun Child
8911!Closer
8609!Seasons
8907!Dreamer
8757!Waiting On You
9260!landrace
8160!Destination
8637!Smooth Wit' Any Groove
8450!Playtime
9273!Rekindling
8456!Crossing Borders
8746!Le Sud
8453!Blind
8092!Soulful
8457!Check It Out
8286!Sticky
8497!Daybreak
9276!Runaway
9301!Float
9306!Relax Your Mind
8183!Divide
8926!Springside
9310!In Your Heart
8090!Sunshine
8181!Feel
8437!No Way Back
9313!11 / Eleven
8545!Exactly
8177!Destiny
8964!Apple Pie & Honey
8966!Eggs Sunny Side Up
8972!Go For A Blow
8175!Chocolate Covered Dreams
8968!Morning Love Affair
8961!Smunchiiez
8970!Funk Flowers
8958!Praliné
9257!Drive Home
8407!Gaia
8446!Passage
8170!LuvnYou
8441!Nothing's Gonna Hurt U
8352!Stay Puff
8355!Silent Color
8350!Smoke Patrol
8167!Stevia Wonder
8356!Sleep Shop
8165!Aqui
8359!Surf Report
8361!Sentimental
8364!Morning Crackle
8367!7th Inning Stretch
8118!Too Young For Secrets
8162!Noodlez
9269!Le Voyage Du Coeur
8540!3UO
8956!Tiger
9315!Sticks & Stones
8933!Sunrise
8156!Coo Lullaby
8436!you left a trace in the sand
8433!the great ocean road
8431!dune child
8429!clay castle ruins
8176!nomads of the sea
8055!wading through the wetlands
8916!Vino
8953!this again..
8767!Home
8370!Valley
8366!Tomorrow
8362!Meadow
8231!Lacuna
9158!Within
8354!Mind Garden
8351!Voyage
8374!Lighthouse
8775!By The Shore
8425!Silience
8447!Phase
8548!Fall Down - Instrumental
9262!Fall Down
8551!Fira
8494!Gone Again
8489!Evening Routine
8487!Prom Night
8476!Back Home
8151!This Is Love
8078!A Day at the Beach
8479!Fireworks
8491!Hometown
8484!Train Station
8543!Distant Travels
8498!Again
8770!Nobody Can See Me
8763!Love Is Weakness
8766!Mindfulness
8149!Cold Heart Women
8148!Heartbreak
8773!Remember
8274!Lazy Pacific
8144!Digital Sex
8768!White Cadillac
8140!San Junipero
8760!Body N Soul
8481!Hideout
8279!Brazil
8558!meadow
43868!dirty shoelace
9245!walnut
9238!light strands
9239!throwback port
9243!takoyaki promenade
8875!embrace
9247!everything you say
9236!thinking of you
8427!Rosewood
7857!Settled
7872!Downtime
7901!A Million Miles
8756!Away with the Fairies
8473!Melting Ice
8781!All Us
9372!Love from NGC 7318
8554!Faces
8005!Interstellar
7998!Stay.
7994!Don't know why
7991!Chinatown
7987!Arcade
7984!Alive
7979!Fat Bao
7977!Lemon
7975!Where I Met You
7971!Patio
7951!Far Away
7948!Flower
7945!Protected
7943!Butterfly
7969!noisy world
7965!Eternal now
7962!Oh Badu
7957!what will you do?
7953!Awakening
7939!Packing My Bags
7934!Sleeping In
7931!Home
7927!Leaving
7924!Thinking Chair
7920!Blankets
7915!B Urself
7912!Ur Ok
7909!moving in
9316!I'm Ready
8207!Vibin' Out
7821!Second Wind
9471!Stagnant
8019!Quietly
8094!Clocks Forward
7816!Effervescent
8104!Rainforest
8058!Coral Dreams
8099!Whale Call
7824!Fried Potatoes
8311!Pickt
8307!Gray
8312!Mr. Balloon Hands
8919!Action
8152!Timelapse
8902!Reminisce
8899!Memories
8179!Clouded Thoughts
8292!Flow
8289!Moonlight
8216!Illusion
8285!Wake up
8220!On my mind
8697!Back to Life
7897!Late Again
8281!Plush Pocket
7889!FrEsH
7898!Power Lines
7895!I Wish It Were (You)
7887!Do You Want To Pretend We're In Love Sometime?
7892!Helplessly
7902!The Finish Line
7885!Welcome Back
7883!The Oldest Man In The Room
8975!Moody
7879!Hummus and Bread
7876!Playful
7873!Build
7869!Nightwatch
7867!Tips and Tricks
8904!Be Alright
7865!Howl
7862!Birds
7859!Drift
7858!6Th Station
7855!Black Garlic
7853!Through
7851!In The Sky
9268!Moon
7848!Wonder
7845!Searching
8410!Sadie
8411!Private Island
8414!Jupiter Moons
8418!Dream Girl
8420!Hibiscus Emoji
7839!New Light
7837!Lost Love
7834!Foggy Road
7830!Wistful
7842!Nimbus
7841!Chiaroscuro
8860!Yo
8252!Customs
8222!Function
8856!Place 2 Be
8369!Yay
8323!Townie
8422!Persuasion
8206!Nice and Easy
8326!Levitate
9271!Mighty
8329!Nostalgic
7826!Back Home
7823!Whistle Song
7822!Hope
7820!Riviere
7819!Holwell
7817!Old Cartoons
7827!Ease Out
8854!Moss
8851!Coastal Town
8789!Droplet
7937!Tiny Sailboat
8225!17
8871!Meaux
8226!Rucker Park
7964!Like I Am
8230!Midnight
8785!Cambria
7815!Our Reflection
7813!Railways
7812!Broken Clocks
7811!Dandelion
7810!Never Felt The Same
7809!Through Walls
7808!Forgot It Was Monday
7806!Procrastinating
8866!Homecoming
8267!Bloom
8863!Tumble's Lullaby
8787!Onteora Lake
8784!Davita
8848!Ocean 5
8240!Astro Love
8243!Dream About U
48102!La Plage
8245!Blue Sky
8248!I Can't Be There
8250!Missing You
8253!Feelin' Alright
48103!Let's Forget Things We Said
8254!Know About It
8256!Ocean Drive
9143!Lilac
7958!Woods
9130!Spring
9128!Oceans
9126!Love
8062!Clouds
9134!Upstate
9504!Sombre
7805!Céleste
7804!Make You Hers
7803!Rain
7913!First Light
9071!Eastway
9069!Tin Toys
9066!Purple
8465!Click
9150!Precarious
8065!White Oak
9085!Focus
9083!Envision
8100!Landing
9076!One Reason
9494!Subaquatic
9492!Bus Taxi
9490!Sun Sets
8910!223°
9501!Blue Skys
9498!Quiet Mornings
9497!Celebrations
9070!Under Leaves
9077!Horse Betting
8604!Sleepwell
9485!Dusk
9484!Slowdrive
8321!Loved
7880!Get Up and Go
9488!Goodmorning
9074!Layover
8097!My Own World
9025!Self Affray
9023!Where Home Is
9020!Cloud Neon
9019!Endless Ether
8864!We Let Go
9065!At Our Core
9062!From Nothing
9481!Bubbly
9479!Rendition
9433!Without You
9478!Believe In You
8590!Homecoming
9221!Opening
9308!While You Sleep
9035!My Love For Her
9033!Daydream
8306!Our Adventures
9337!Wistfulness
8113!Night Walk
9118!Migration
7875!Cliffside
9120!Walks By The Pond
9081!Destiny
9079!Simple Words
7919!Mirai
10003!Breakfast w Bastien
10002!Vibe Vibe
9997!Demo 13 v2
10001!Sofa Stories
10000!Pick Up
9090!Flutter
9092!zzz...
9087!Continual
9041!Careless
9038!Slightly Improvised
8133!Something Warm
8508!Forest Lake Walk
8068!Morning In The Cafe
9055!Forward
9053!Slope
9051!Bewildered
8264!Leaving For Good
9048!Embers
8131!Dusk
9045!Mother Nature
8930!Cloud Dance
9049!Island Boy
8102!Into The Wind
8974!Sundown
8036!Ocean Patio
8115!When To Say Goodbye
8718!Can't Find the Words
9011!Because I Was Lonely
9008!Be Okay
8026!Comfort
9014!Tsuki's Tears
7988!Velocities
8776!Caught In The Rain
8891!Awake
8837!Never Forget
8657!blankets
7980!The Shore and You
8824!Remember
8109!Apple Flower
7974!Small Things
8991!Blur
8567!Snug
7982!Watercolor
7985!Collages
7976!Fireplace
7972!Winter Winter
7968!Nights Like These
7993!Swimming
7990!Sunbreak
8105!After Dark
8027!Hibernation
8085!bringmesun
8345!Kyiv
8341!And Now I've Found You
8134!doing laundry
8039!Ochre
8320!Is Nostalgia An Emotion?
8200!Cruisin'
8127!Far From Home
9435!In Loving Memory
8075!Hypnagogia
8288!Sonar
8291!Persist
8283!So Unnecessary
9421!Peaceful Sleep
8388!Snacks Pt. 1
9423!Aerials
9424!Pacific
9428!Let's Stay Inside
8290!Cool Side Of The Pillow
8023!digital dreams
7843!polarbeer
8021!rolling down this lazy wave
8033!by & by
8013!In Time
7992!Viaduct
8040!Wash
8016!Ever Forward
8030!Flashes of Calm
7997!Faraway
8000!Too Late
8002!Dojo
8003!Ukon
8010!Swing For Me
8006!Let It Go
8008!Aries
9411!Asymptotic
7995!Fond Memories
9444!A Deeper Understanding
9021!fiveyearsago
7906!Uplift
9406!Fields
9459!A Beautiful Salad Bowl
8685!Dans la Salle à Manger
9450!Dessous
9451!Camille & Leo (interlude)
8810!Du Bassin au Muret
9454!1999
9324!Les Vacances
9455!Les Bonnes Choses
9430!Goodnight
7923!Such Great Heights
9441!King Street
9438!Crickets
9432!Leaf And Wind
7996!When The Green Fades To Grey
9367!Birds Fly Higher Than The Moon
9413!Speed Of Warmth
9415!New Place, Same People
8867!Unshifted
7911!Bedscape
7910!Memory Ride
7908!Be Still
7903!Pleasant Beach
9401!Last Night
9418!Time
9196!Icepath
9203!Where We Met
9383!Warmer Days
9379!Awake
9377!Childhood Days
9374!Fog
9052!Warm Feeling
8815!Fate
9027!Times Ahead
9392!Life Is a Dream
9389!Wake Up
9385!Traveling Through Time
8263!Ode To Life
9404!Love
9408!Sky
8705!Everlasting
9360!Ocean Alley
9357!Crema Cafe
9352!Cocktail Hour
8607!Tamarind
9364!Central Coast
9355!Sails
8266!Lagoons
9363!Jazz Cabbage
8522!Late Days Of 96
9343!As Tides Polish Stones
8694!Early Days Of 96
9285!Calm
8987!River (Blue)
9250!Staring at the Sun
8547!Little Spirit
7967!Sundew
9395!Casual
9320!Wake Up
9305!Need Someone
9322!Inside
8147!Fuzz
9168!Nightscape
9334!Caffeine
8971!Hibiscus
9312!Toft
9325!Air Curvatures
9280!Nightglow
9148!Nightfall
9278!Day and Night
9275!Daydream
9272!Daylight
9259!Small (Gravity)
8536!Novel (Calm)
9255!Manner (Forms)
9447!Vinho Verde
8083!You're Asleep So I Gotta Keep It Down Shh
8688!Home Video
8514!Old Friends
9219!Growing Apart
7925!Upset (hold it in)
9222!Keep Going
9228!Reflection
9225!Tumbling
9224!Fox
8037!Cliff Of The Horizon
8261!Drifter
8985!Mozambique
8707!autumn breeze
8080!YesPlease
8391!Chasin Daisys
7922!A Tribe Called Tenz
7840!Sunsets
8827!Changing Lanes
7833!Sunlit
8117!back when it all made sense
9003!jam session
7914!London Love Letters
8405!Chrysalism
9339!Highland
9237!Waterfall Eyes
9010!Origin
9341!Lily Pads
9229!Scout
8751!Midtown Rooftop
9232!Unlisted
9175!Driftaway
9651!Waiting for You
9785!Time to Shine
8095!Finally Home
9448!Long Time Ago
7981!Glory Days
9781!Happy Place
8650!Journeys
9652!Never Ending
8280!Stolen Time Capsule
9655!The Dawn Coloured Us In
9717!Point Of No Return
9384!Last Frontiers
9700!Oceanharp
8164!The Map Plotted Us In
8275!Life Force
9331!ny90
9873!Tides Turn
9874!Two Moons
9872!Elsewhere
9332!Imagination
9729!Staying In
10078!Firefly Field
10077!Cap's Café
10074!Under the City Stars
10076!Beaver Creek
10075!Canary Forest
9295!Silk
9427!Pepper Lights
9475!Sleep First
10034!Way Away
10027!Feather
10035!The Noise in Pictures
10033!Woodpecker
10031!Lunar Cycles
10032!Backyard Puddles
10022!Bookshelves
10023!Colors Fade
10021!Butterfly
10017!Witch Hat
10015!Rest Until Dark
9639!Can't Hear...
10135!Blurry
10150!Cold Outside
10144!Perfume
10142!New Horizons
10152!Distance
10139!Sunday Mornings
10128!The Ride Home (interlude)
10148!False Hope
10134!One Last Call
10140!Train Ride
10136!Mirage
10130!Sleepover
8581!Thursday Morning
9735!Truthful
9653!Birthday
8192!Embers in the Dark
10315!String Along
8761!Blue Dawn
8888!Ful Off
10247!Trenches
8777!First Lights
8137!burn my mind
9347!Umbrella Pine
10265!Habitat
10259!Anemone
10262!Willow
10254!Soil
10255!Plants
10257!Droplets
10251!Pine and Oak
10249!Serendipity
10245!Upstate
10263!Wildlife
10243!Maple Leaf Pt.2
9734!Indoors, Puzzles
8550!Plant Care
9731!Midday Hike
9727!Cohesive
9718!Ghost Towns
9178!State Fair
9002!Fifteen Km
9917!Flushing the Stairs
8681!Island Sanctuary
9042!Kelp Forest
9641!Tide Pool
9927!Zenith
9925!With Time
9923!What Was Before
9921!Aqueduct
9919!Paved Paths
9915!Dancing Droplets
9913!Hidden Structure
8236!Air Molecules
10459!Still Life Dreamtime
10458!Magenta Forever
10452!Hotel Lobby Birthday Party
10446!Bluetooth Ringtone (interlude)
10450!Not A Cloud In Sight
10460!Deeper
10454!Creswick
9771!Her Eyes
9775!Perspectives
8599!Otherside
9759!Be
9013!Orange On The Blue Palette
8063!Forest Speak
9696!Reverse Clock
11251!Through Trees
11249!Flowers
11248!Cloud Carpets
11247!Loving Someone You Lost
11246!Peaches
11245!Harbor
11244!Lilo
11243!Sugarless
9166!Afterlife
9663!Spring
9754!Potion
9517!Departure
11771!Departure
11777!Longing
11768!Oasis
11778!Melancholy
11773!Seascape
11770!Hereafter
9783!After All
9284!Anywhere But Here
8072!comfortable
7929!Wrong Way
7955!Cozy Fire
10320!Ocean View
7966!Oceania
7930!Girls Just Wanna Have Sun
9299!Cascada
8171!p i c k m e u p
9307!Harvest
9261!All In Good Spirit
9506!Longing
8202!rainy day loop
11743!Reality.
11741!Vivid.
11737!Parallel.
11742!Fantasy.
11735!Limitless.
9708!Come Back To Me
9756!Elderwood
9535!Silhouettes
12129!Where The Streets Are Cold & Lonely
12128!Today Feels Like Everyday
12124!Small Town Palm Trees
12125!Lax Incense
9212!bright mornings
9684!hello, goodbye
9335!vhs tapes 1993-1996
9659!fairfield boathouse
7814!Murmuration
11235!Bloom
11233!Home Court
11231!Day One
11229!Déjà Vu
11227!Toofpick
11225!Flashback
10553!Who Knows
11129!it's ok, i only have tears in my third eye
8193!be here now
8918!Midnight Service
8995!feelinglow
8920!Finding You
8698!grandiose soul
7871!Last Snow
9303!Reliving
9304!Yerry Hill
9145!Adieu
8519!Coupe_90
10321!Cruisin
10547!Holding No Hands
10279!Snowland Sunset
10311!There and Back
10335!Focus
10339!You and I
8398!Green House
13005!Golden
10556!Peninsula
9297!Beyond Clouds
9061!sopha
8741!ebb//flo
10554!Desire
11135!the last day of september
13001!Coda
13009!Momentary Loss
12999!Ambleside
13003!Barrows
13015!Maple
13007!Evenfall
13013!Splendour
13014!Woodnote
12997!Kinsfolk
11145!face to face with the great nothing
11143!from nothing to nothing (leitmotif)
11141!at the end of the day
11139!ouroboros
11137!i miss you every day
11133!answering machine tape loop
11131!summer fades away
12136!Runaway
11159!Alone
11157!Two For Joy
13092!Cascade
11161!Bottle of Birdsong
11155!Little Sparrow
11153!Finally Home
11151!Candlelit
11149!Unfurl
14981!Lonely Waves
15181!A Feeling That Something Has Happened Here
15001!70 Avenue
15000!Zodiac
14998!Naked Sunday
14995!Dreamlover
14994!Taste of Heaven
14983!Playful Obsession
14991!Blue Moon
14989!Lost Soul
14987!Spiritual Mind
14985!Roses n Flames
15235!Self Luv
15238!Reflect
15230!Wish
15228!Mario Kart
15237!On The Moon
15236!Samething
15226!Skates
15224!By Chance
11264!And So Do The Memories
11272!Outro
11268!All That Remains
11372!Interlude
11262!The Context Fades
11260!Intro
12094!Passenger
11945!Passenger
13061!Charmy
13059!Charmy
14958!Simplexity
17089!Dive
17088!Vintage
17090!Low Rider
17087!Cruising
19056!In The Shade
19055!Poolside
17913!In The Shade
17915!Poolside
15018!Morning Dew
17910!Morning Dew
16513!Fallen
16512!Illicit
16511!Vault
16510!Lance
20279!Boardwalk
20285!Have Doughnut
17925!Dusk
17944!Aftersome
17943!Momo
17947!Dreamstate
17938!Antematter
17937!Contemplation
17929!Down
17927!Rover
17946!Opia
17933!Lavish
17931!New Moon
17941!Dawn
21781!Almost Home
21785!Slopes
21783!Belly Breathing
21784!LuvnYou
21782!Be Here Now
20287!The World We Were Born In No Longer Exists
20121!Airplane Mode
20332!Magnitude
20126!Badlands
20125!Wayfare
20127!Tether
20124!Layover
20123!Safe Haven
20120!Trainspotting
20122!Caravan
20119!Viatecture
20295!Not Afraid Of Ghosts
21646!Esfera
21658!Puesta De Sol
21657!Cueva
21656!Ámbar
21654!Leña
21653!Libélula
21652!Pie in the Sky
21651!Luz
21650!Saudade
21649!What If I Told You
21648!Glaciar
21647!Cabaña
20297!Grit In The Lens
20293!Lost In The Fire
20291!All The Tired Ways
20289!Remedy
20283!Grim Canaria
20281!Objects With Intent
21661!Reason
20565!Shine
20563!Places
20561!Fallin'
21660!Memories Pt.2
21659!Memories Pt.1
20303!The World We Were Born In No Longer Exists
22940!Chop City
22939!Halklow
22938!Passing Notes
22937!By The Window
22936!The Way We Were
22935!Same Old Circles
22934!Chit Chat
22933!When I Get Up In the Morning
22794!Perspective
22793!Clarity
22792!Gratitude
22791!Move
22790!Vitamin D
20305!Objects With Intent
20309!Objects With Intent
20307!Not Afraid Of Ghosts
20302!All The Tired Ways
20300!Have Doughnut
22994!Saturday Sunrise
23189!Little Windows
23190!Driftwood
23191!Bird In The Floorboards
23192!There and Back
23193!Inside a Saltwater Room
23194!Time Went By
23195!Blue
23196!Southwesterly
23188!Where The Sun Goes
23348!Pathways
23347!Undiscovered
23346!Rowengartner
23345!Ultraviolet
23344!Roominate
23343!Lake Winnipesaukee
23342!Leches On the Menjay
23341!Transparent
23340!Deja
21742!Sirens
23338!This Too Shall Pass
23337!Odyssey
23336!Seeds for Tomorrow
23335!Looking In
23169!Warmth
23161!Far Wandering
23175!Years Ago
23173!Waiting
23171!Central Hall
23167!Welcome Home
24832!Getting Soup
24831!I Will Never Stop Writing Songs About the Rain
24830!Learning How to Skateboard
24829!Fireworks Festival
24828!Man I Miss My Cats
24826!Setting Up Our Beds in Minecraft
24825!Library Card
24824!Tournament Arc
24823!Just Put Up Some String Lights
24822!I Main Samus Now
23165!Waiting On You
23163!Sun Petal
23159!Offshore
23073!Everything's Gonna B Ok
23315!I Miss the Magic
23069!Hope Island
23067!Nomad
23065!Jasmine
23063!Sorry Matthew
23061!Sketchbook Memory
23314!Two Thousand Miles
23057!Perfect Storm
23270!30AU
23268!Recurring Thoughts
23272!Creation
24767!Polaroid
23280!Together
23278!Communal
23276!Life
23274!Recuperate
24699!Hung Up
24721!dans le palais
24723!dans le palais
27504!Waiting
27503!Turbulence
27502!Waybackwhen
27501!Everlight
27500!Soulsounds
24841!All Those Years, All Those Nights Ago
24851!Forever Let it Ring
24849!We Go on, or Off, for Solace
24847!All Memories are Fiction Again
24845!Cry of a Hollow Man
24843!Sustain the Longing Notes
24839!Is Longing a Feeling or an Emotion?
24837!We Filled Up the Silence
24835!Away from Home
30130!Leaf Contour
30137!Reunion
30141!Repent
30131!Letters
30308!Green Tea
30140!Riverside
31601!Solitude
31615!Chilled Memories
31611!Before Nightfall
31599!Quiet Night Rain
31598!Moody
31609!La Bohème
31600!Phone Call
31613!Stop Breaking My Heart
31614!I Need Your Attention
31610!Chill'n
31608!Vision Nocturne
31516!Tropical Midnight
31591!Night Fishing
31589!Lose Her Way
32888!Glow
32978!Blue Moment
32885!Timelapse
32854!Reflections
34372!Montauk Paddling
34162!Caramel
28905!Eclaircie
28903!Bronea
28901!Parasol
28899!Pampaya
28897!Valse
28895!Kokon
35355!Summer in Cotuit
34242!Nectarine
36650!Rooftop Breeze
36925!A Reminder
35507!Full Circle
36940!Low Tide
41648!Gravity
41649!Cycles
41650!Street Lights
41651!First Contact
41652!Passing Time
41653!Awaken
41654!Changing Winds
41655!Skipping Stones
41656!Falling Out of Orbit
36942!After Hours
41693!Memories of When....
41695!Clocks Running
41700!The Flash before my Eyes
41698!Halflife
41702!Hyperspace
41687!Sundials
41689!In Minutes
36919!The Field from Spirited Away
34328!Monolith
41938!Berry Drive
42445!Hold me Tight
43683!Break
43682!Starlink
43681!Phases
43680!Know by Now
43679!Home
42056!Passing Storm
36916!It'll Last a Million Years
37131!Snoopy's House
36918!Looking out the Bus Window
36921!Arthur in Snow
37132!Winter Soccer Practice
36922!Treecko is a Cool Starter
37133!Penpals Perhaps
37127!Apple Turnover
43908!Memory
43907!Soft Spot
43906!Envy You
43905!New Places
43904!Orange Trees
43903!Flight Mode
43902!Sleep Walker
44900!Lookaway
45233!About It
45232!Nightcrawler
45231!One for Mac
45230!Funky Record
45229!Oh Let's Ride
45073!Snuck Past the Fireplace
45071!Small Whispers
45069!Reginald
45067!Power Off
42247!Zoned
42245!Stopped Short
42243!Saved For Sunset
42241!One Eye Open
48117!Empty Rooms
48093!6am
48092!Lights Off
48091!Bubble Bath
48090!Salt Lamp
48089!Sueños
48088!Another Day
48087!Early Rise
49441!Crush
49440!Up Early
49439!Spring
49438!Cosmos
49437!Slow Burn
49436!Sippin'
49429!Snap Back
49428!Lavender
49426!Kaleidoscope
49425!Dreaming
51080!Oasis
51082!Shorty
51084!Twilight
51086!In the Night
51088!Summer Vibe
51078!Cloud Zone
49381!Delicate
55318!allwehave
55319!Peace Resting
55315!See You Cross Country
55316!Addison
55314!Tying Knots
55312!Ode to Scotty
55311!Upstream
55317!Fly High Newborn
55313!Coffeebreak
55310!Peaceful Dissociation
53592!Let Go
58841!Still Looking
58840!Longest Wait
58839!Follow the Rabbit
58838!Pending
58837!Offroad
58836!In Circles
58846!Trainride
58834!Steady
58833!Apple
58861!Waiting for that Phonecall
58860!Swell
58859!Very Last
58858!Daylight Drift
58857!Sunny Side Up
58856!Daydream
58855!Shung
58854!Thrillseeker
58853!Balcony
55130!Lost Woods
53594!The Tourist
55163!It's Okay
55235!Inhale/Ad Astra
53596!Transition
60622!Let it go
60621!Morning Star
60620!Sunset Drive
60619!You
60618!Sex on the Backseat
60617!Take it Eazy
60616!Piña Colada
60615!Late Night Drive
60614!Forever young
60573!Emotions
60572!Bikini Palm-trees
60571!Beautiful
58823!The Tourist
58001!Once
60306!Color of the Darkness
62379!Roadtrips
62171!Tomorrow
62378!Forgetting
62377!Dusty Records
62376!See You Soon
62375!Distant Memories
62374!What You Left Behind
62373!Alone
62372!The Breeze
62371!I Miss You
62370!Do Not Go
62280!Through Line
60832!Oslo-S
60834!Scholastique
60836!Earl Gray
60838!Super Chill Vibes 5000
60840!Suzuki
60842!Mahogany
65379!Let Go (Philanthrope Remix)
64125!Fade out
64124!Things Fall Apart Pt.2
64123!Serenade
68157!Snug
64120!Hindsight
64119!Move Like That
64118!Panda
64117!Beavis pt.2
64098!Satin
64097!Setbacks
64096!Loner
64095!Coast
64094!Back Again
64093!No Hassle
64092!Bloom
64091!Roam
65489!Inhale/Ad Astra (Boukas Remix)
68327!Naturally Flavored
68324!Forward Movement
68323!Fall Out
68322!Clapper's Delight
68321!Back Track
68325!It All Connect
68328!Rest Assured
68326!Knocked
68353!Speedin'
68352!S2000
68351!Night Moves
68350!Twin Turbo
68349!Interlude Ride
68348!Slow Lane
68347!Acura Coupe
68346!I-285
68360!Transition (El Train Remix)
69640!Jade
69646!Last Hand
69641!Linha de Passe
69648!In Spirit
69645!Vers le Ciel
69642!Dreams & Reality
69924!Evian
69923!Every Cloud
69916!n64
69915!Widen
69914!Push to Open
69913!Joop
69912!Winter Wonderland
69906!rain world
69905!melina
69904!even though i tried
69903!switch up / down for u
69902!every way u say my name
69901!palace
69900!north
69899!ranni
65383!Winter Shore
69949!Stay Like This
69947!Go back to the Jungle
69951!Stay Like This
69948!Transformations
69950!Company
65411!Stay
71629!Slinky
71644!High Beams
74258!Kauai
74265!Meadow Terrain
75139!L'aventure
75732!Spirals
75141!Lobby call
71621!Foresight
75143!On the Run
75137!Impulse
75745!Looming
75835!Oregon Coast
73162!Friends
78346!December, Too
73166!Always
73168!Growing Pains
73164!Sunkissed
75538!I Don't Want Love
64054!I Don't Want Love
64040!One for Florian
75541!Seu Trio
75544!You Bring Me Life
64045!Cut Free
75547!Last One
75546!That Summer
75545!Hold it Down
75543!1978
75542!Hope
75540!When All I Heard Was Artifacts
75539!Cantar
64036!Curtain Call
64038!High Hope
64043!In the Sun
64047!Sleeping Norboo
64050!Autumn Turned Winter
64056!Harp Trees
79272!Early June
74856!Light of World
77527!Guitar Shop
74855!High Hope
77541!Hope It's Not
74864!I Don't Want Love
79268!Farewell
79271!In My Room
79267!Back Home
74866!Curtain Call
74805!requiem
74870!Light of World
75527!Sleeping Norboo
75526!I Don't Want Love
74867!Sleeping Norboo
74807!miles away
74803!nightshift
74801!traces
75571!Curtain Call
78926!Growing Season
78943!Velvet
81156!Engines
83282!WantU2Stay
83262!Tarkwa Bay
83337!Lagos Sundown
83340!Emem
81378!Midnight Veil
81240!Tropico
82321!Background
84241!Spykids
82325!Dry Leaves
82333!Driving
85214!My Steeze
82331!Filaments
85273!Shoegaze
TRACK_EOF
)

# 去除字符串首尾空格
trim() {
    local var="$*"
    var="${var#"${var%%[![:space:]]*}"}"
    var="${var%"${var##*[![:space:]]}"}"
    echo "$var"
}

# 解析嵌入的曲目
parse_tracks() {
    local line id name
    while IFS= read -r line; do
        [ -z "$line" ] && continue
        if [[ "$line" =~ ^([^!]+)!(.+)$ ]]; then
            id_raw="${BASH_REMATCH[1]}"
            name_raw="${BASH_REMATCH[2]}"
            id=$(trim "$id_raw")
            name=$(trim "$name_raw")
            name_escaped="${name//\'/\'\\\'\'}"
            id_escaped="${id//\'/\'\\\'\'}"
            echo "${name_escaped}|${id_escaped}"
        fi
    done <<< "$TRACKS"
}

# 主逻辑
main() {
    mkdir -p "${CACHE_DIR}"
    local parsed_tracks=$(parse_tracks)
    [ -z "$parsed_tracks" ] && { echo "错误：无有效曲目"; exit 1; }

    local selected=$(printf "%s\n" "$parsed_tracks" | dmenu $DMENU_ARGS | head -n1)
    [ -z "$selected" ] && { echo "用户取消选择"; exit 0; }

    local name=$(echo "$selected" | cut -d'|' -f1 | sed "s/'\\\'\"'/'/g")
    local id=$(echo "$selected" | cut -d'|' -f2 | sed "s/'\\\'\"'/'/g")
    local cache_file="${CACHE_DIR}/${id}.mp3"

    notify() {
        command -v "notify-send" &> /dev/null && notify-send "Chillhop" "$1"
    }

    if [ ! -f "${cache_file}" ]; then
        notify "正在下载：${name}"
        echo "下载中：${name}"
        if ! curl -sSL "${STREAM_BASE_URL}${id}" -o "${cache_file}"; then
            notify "下载失败：${name}"
            echo "下载失败"
            rm -f "${cache_file}"
            exit 1
        fi
        notify "下载完成：${name}"
    else
        echo "使用缓存：${cache_file}"
    fi

    notify "开始播放：${name}"
    echo "正在播放：${name}（按 q 退出）"
    ${FFPLAY_PATH} -nodisp -autoexit "${cache_file}"
    notify "播放结束：${name}"
}

main
